package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.Account;
import com.ktwlsoft.archivemanage.domain.dao.entity.ReportLog;
import com.ktwlsoft.archivemanage.domain.dao.repository.ReportLogMapper;
import com.ktwlsoft.archivemanage.service.security.UserPrincipal;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ReportLogRepositoryService {

    @Getter
    private final ReportLogMapper reportLogMapper;

    public ReportLogRepositoryService(ReportLogMapper reportLogMapper) {
        this.reportLogMapper = reportLogMapper;
    }

    public int saveLog(ReportLog.OperationType operationType, Long reportId) {
        Account account = UserPrincipal.getCurrentUser();
        ReportLog reportLog = new ReportLog();
        reportLog.setOperateType(operationType);
        reportLog.setReportId(reportId);
        reportLog.setOperaterId(account != null?account.getId():0);
        reportLog.setOperateTime(new Date());
        reportLog.setOperater(account != null?account.getRealName():"");
        return reportLogMapper.insert(reportLog);
    }
}
